# Maintainer: Andy Postnikov <apostnikov@gmail.com>
pkgname=php81-pecl-swoole
_extname=swoole
pkgver=6.0.0
pkgrel=0
pkgdesc="Event-driven asynchronous and concurrent networking engine with high performance for PHP 8.1 - PECL"
url="https://pecl.php.net/package/swoole"
arch="all !x86 !armv7 !armhf" # no 32-bit support
license="Apache-2.0"
_phpv=81
_php=php$_phpv
depends="
	$_php-pecl-brotli
	$_php-curl
	$_php-mysqlnd
	$_php-openssl
	$_php-pdo
	$_php-sockets
	"
makedepends="$_php-dev
	brotli-dev
	c-ares-dev
	curl-dev
	linux-headers
	libpq-dev
	liburing-dev
	nghttp2-dev
	openssl-dev
	sqlite-dev
	"
source="php-pecl-$_extname-$pkgver.tgz::https://pecl.php.net/get/$_extname-$pkgver.tgz"
builddir="$srcdir"/$_extname-$pkgver
subpackages="$pkgname-dev"
replaces="php81-pecl-openswoole"

case "$CARCH" in
	ppc64le|s390x|loongarch64) makedepends="$makedepends libucontext-dev" ;;
esac

build() {
	sed -i s/OS_SHOULD_HAVE_LIBRT=1/OS_SHOULD_HAVE_LIBRT=0/ config.m4
	case "$CARCH" in
		ppc64le|s390x|loongarch64) export LDFLAGS="$LDFLAGS -lucontext" ;;
	esac
	phpize$_phpv
	./configure --prefix=/usr \
		--with-php-config=php-config$_phpv \
		--with-nghttp2_dir=/usr \
		--enable-mysqlnd \
		--enable-openssl --with-openssl-dir=/usr \
		--enable-sockets \
		--enable-swoole-curl \
		--enable-swoole-pgsql \
		--enable-swoole-sqlite \
		--enable-brotli --with-brotli-dir=/usr \
		--enable-iouring \
		--enable-cares
	make
}

check() {
	# needs extra services to test all suite
	$_php -d extension=modules/swoole.so --ri swoole
}

package() {
	make INSTALL_ROOT="$pkgdir" install
	local _confdir="$pkgdir"/etc/$_php/conf.d
	install -d $_confdir
	echo "extension=$_extname" > $_confdir/50_$_extname.ini
}

sha512sums="
b0d7a8482d81e389e1a7ccaf72ebb3dda47651ef8c6a09fbf9ce8e4f14c642f91367d578ba62753a7b13ef900466d9f8688e4ed7c271c0bd76c46518db5eef79  php-pecl-swoole-6.0.0.tgz
"
